<?php
defined('_JEXEC') or die('Restricted access');
$db					=& JFactory::getDBO();	
$query				= "SELECT id FROM #__phocagallery_categories WHERE published = 1 AND approved = 1 ORDER BY id DESC LIMIT 0, 1";
$db->setQuery($query);
$catid				= $db->loadResult();

$queryp				= "SELECT cc.*, COUNT(p.id) AS img, p.filename
						FROM l7epi_phocagallery_categories AS cc
						INNER JOIN l7epi_phocagallery AS p ON cc.id = p.catid
						WHERE cc.id = 1 GROUP BY cc.id";
//echo $queryp;
$db->setQuery($queryp);
$rows				= $db->loadObject();
//echo $rows->id;
//print_r($rows);
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
	<td align="left" width="520">
    <?php 
	echo '<div style="margin-bottom:5px;"><img width="500px;" src="images/phocagallery/thumbs/phoca_thumb_l_'.$rows->filename.'" /></div>';
	?>
    </td>
    <td valign="top"  align="left">
    <?php 
	echo '<div style="margin-bottom:25px;margin-top: 5px;text-align: left;width: 160px" class="pg-cats-name '.$this->tmpl['class_suffix'].'"><a href="index.php?option=com_phocagallery&view=category&id=' . $rows->id . ":". $rows->alias. '">'.$rows->title.'</a> ';
					if ($rows->img > 0) {
						echo '<br /><span class="small">'.date('d M Y',strtotime($rows->date)).' | '.$rows->img.' pictures</span>';
					}
		echo '</div>';	
	?>
    </td>
</tr>
</table><br />

<?php
echo "\n\n";
echo '<div id="phocagallery-categories-detail">'."\n";
$categoriesboxwidth = ($this->tmpl['categoriesboxwidth']) ? $this->tmpl['categoriesboxwidth'] : 180 ."px";
$count = 0;
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin: 0px;padding:0px">';
for ($i = 0; $i < $this->tmpl['countcategories']; $i++) {
	if ($count == 0){
		echo "<tr>";
	}
	echo '<td valign="top">';
		echo '<div class="pg-cats-box-img"><a href="'.$this->categories[$i]->link.'">';
		if (isset($this->categories[$i]->extpic) && $this->categories[$i]->extpic) {
			$correctImageRes = PhocaGalleryPicasa::correctSizeWithRate($this->categories[$i]->extw, $this->categories[$i]->exth, $this->tmpl['picasa_correct_width'], $this->tmpl['picasa_correct_height']);
			echo JHtml::_( 'image', $this->categories[$i]->linkthumbnailpath, str_replace('&raquo;', '-',$this->categories[$i]->title), array('width' => $correctImageRes['width'], 'height' => $correctImageRes['height'], 'class' => 'pg-cats-image',  'style' => ''));
		} else {
			echo JHtml::_( 'image', $this->categories[$i]->linkthumbnailpath, str_replace('&raquo;', '-',$this->categories[$i]->title), array('class' => 'pg-cats-image', 'style' => ''));
		}
		echo '</a></div>';
		echo '<div style="margin-bottom:25px;margin-top: 5px;text-align: left;width: 160px" class="pg-cats-name '.$this->tmpl['class_suffix'].'"><a href="'.$this->categories[$i]->link.'">'.$this->categories[$i]->title_self.'</a> ';
					if ($this->categories[$i]->numlinks > 0) {
						echo '<br /><span class="small">'.date('d M Y',strtotime($this->categories[$i]->date)).' | '.$this->categories[$i]->numlinks.' pictures</span>';
					}
		echo '</div>';
	echo '</td>';
	if ($count == 3){
		echo "</tr>";
	}
	$count++;
	if ($count > 3){
		$count = 0;
	}
	/*
	echo '<div style="width:'.$categoriesboxwidth.';" class="pg-cats-box-float">'."\n";
		echo '<div class="pg-cats-box '.$this->tmpl['class_suffix'].'">'."\n"
				.'<div class="pg-cats-box-img"><a href="'.$this->categories[$i]->link.'">';
			if (isset($this->categories[$i]->extpic) && $this->categories[$i]->extpic) {
				$correctImageRes = PhocaGalleryPicasa::correctSizeWithRate($this->categories[$i]->extw, $this->categories[$i]->exth, $this->tmpl['picasa_correct_width'], $this->tmpl['picasa_correct_height']);
				echo JHtml::_( 'image', $this->categories[$i]->linkthumbnailpath, str_replace('&raquo;', '-',$this->categories[$i]->title), array('width' => $correctImageRes['width'], 'height' => $correctImageRes['height'], 'class' => 'pg-cats-image',  'style' => ''));
			} else {
				echo JHtml::_( 'image', $this->categories[$i]->linkthumbnailpath, str_replace('&raquo;', '-',$this->categories[$i]->title), array('class' => 'pg-cats-image', 'style' => ''));
			}

					echo '</a>'
				.'</div>'."\n"
			.'<div style="margin-bottom:25px;text-align: left;width: 160px" class="pg-cats-name '.$this->tmpl['class_suffix'].'"><a href="'.$this->categories[$i]->link.'">'.$this->categories[$i]->title_self.'</a> ';
					if ($this->categories[$i]->numlinks > 0) {
						echo '<br /><span class="small">'.date('d M Y',strtotime($this->categories[$i]->date)).' | '.$this->categories[$i]->numlinks.' pictures</span>';
					}
		echo '</div>
		<div style="clear:both"></div>'."\n"
		 //.'<div style="clear:both;"></div>'
	.'</div></div>'."\n";
	*/
	
}
echo '</table>';
echo '<div style="clear:both"></div>'."\n";
echo '</div>'."\n";
echo "\n";
?>